﻿using AutoMapper;
using Easy.Common.Results;
using Easy.Services.Dtos;
using Easy.Services.Entities;
using Easy.Services.Interface;
using Microsoft.AspNetCore.Mvc;

namespace Easy.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DataBaseController(IMapper _mapper,IDatabaseService  _databaseService) : BaseController
    {
        readonly IMapper mapper=_mapper;

        readonly IDatabaseService databaseService=_databaseService;

        [HttpPost]
        public APIResult Add(DatabaseDTO dto)
        {
            APIResult result = new();
            var model = mapper.Map<Database>(dto);
            model.SetModelBase(tokenModel: TokenModel, isInit: true);
            var res = databaseService.Add(model);
            result.Success = res > 0;
            result.Message = res > 0 ? "添加成功" : "添加失败";
            result.Data = res;
            return result;
        }

        [HttpGet]
        public APIResult GetStatistics()
        {
            APIResult result = new()
            {
                Data = databaseService.GetStatistics(),
                Success = true
            };
            return result;
        }


    }
}
